/*
 * @lc app=leetcode id=155 lang=cpp
 *
 * [155] Min Stack
 */
class MinStack {
    deque<int> dq;
    deque<int> stack;
public:
    /** initialize your data structure here. */
    MinStack() {
        
    }
    
    void push(int x) {
        dq.push_back(x);
        if (stack.empty()) {
            stack.push_back(x);
        } else if (stack.back() >= x) {
            stack.push_back(x);
        }
    }
    
    void pop() {

        if (dq.empty()) {
            return ;
        }

        if (dq.back() == stack.back()) {
            stack.pop_back();
        }

        dq.pop_back();
    }
    
    int top() {
        if (dq.empty()) {
            return -1;
        }       
        return dq.back();
    }
    
    int getMin() {
        if (stack.empty()) {
            return -1;
        }
        
        return stack.back();
    }
};

/**
 * Your MinStack object will be instantiated and called as such:
 * MinStack* obj = new MinStack();
 * obj->push(x);
 * obj->pop();
 * int param_3 = obj->top();
 * int param_4 = obj->getMin();
 */

